#include "GameServer.h"
#include "EndianCast.h"
#include "../../include/GTProto.h"
#include "ProxyMgr.h"
#include "Proxy.h"

CGameServer::CGameServer( utility::network::pipe * pPipe ):
IServer(pPipe)
{

}


CGameServer::~CGameServer(void)
{
}

void CGameServer::Release()
{
    delete this;
}

void CGameServer::on_receive( const char * message, uint32 message_length )
{
    uint32 nProtoID = ntohl(*(uint32 *)message);
    switch(nProtoID)
    {
    case GT_SET_DEST_SERVER_NTF_ID:
        {
            GT_SET_DEST_SERVER_NTF_PKG * pkg = (GT_SET_DEST_SERVER_NTF_PKG *)(message + sizeof(nProtoID));
            CProxy * pProxy = CProxyMgr::Instance()->Find(ntohll(pkg->nProxyID));
            pProxy->ConnectServer(ntohl(pkg->nServerIP));
        }

        break;
    case GT_BACK2_DB_SERVER_NTF_ID:
        {
            GT_BACK2_DB_SERVER_NTF_PKG * pkg = (GT_BACK2_DB_SERVER_NTF_PKG *)(message + sizeof(nProtoID));
            CProxy * pProxy = CProxyMgr::Instance()->Find(ntohll(pkg->nProxyID));
            pProxy->DisconnectServer();
        }
    }
}

void CGameServer::on_established()
{

}

void CGameServer::on_disconnected()
{

}

void CGameServer::on_error( int32 error_code, const char * error_message )
{

}
